<template>
  <div
    style="height: 100%"
    v-loading="loading"
    element-loading-text="系统加载中..."
    element-loading-spinner="el-icon-loading"
    element-loading-background="rgba(0, 0, 0, 0.8)"
  />
</template>

<script>
import {singleSignLogin} from '@/api/login'
import { setToken } from '@/utils/auth'

export default {
  name: 'Login',

  data() {
    return {
      loading: false
    }
  },

  created() {
    this.signOn()
  },
  mounted() {
    // particlesJS("particles-js", particlesJson);
  },
  methods: {
    signOn() {
      this.loading = true
      const href = window.location.href
      singleSignLogin({
        tenantCode: '',
        caseCode: this.$route.query.code,
        redirectUrl: href.split('?')[0],
        clientType: 'pc'
      }).then(res => {
        if (res.code === 200) {
          setToken(res.token)
          this.$store.commit('SET_TOKEN', res.token)
          this.$router.push({ path: '/' })
        } else {
          this.$alert('单点登录失败', '登录失败', {
            confirmButtonText: '确定',
            callback: action => {
              window.history.back()
            }
          })
        }
      }).catch(error => {
        console.log(error)
      }).finally(() => {
        this.loading = false
      })
    }
  }
}
</script>

<style rel="stylesheet/scss" lang="scss">

</style>
